from urllib import request
import json

# url = 'http://httpbin.org/get?name=fcb'
# response = request.urlopen(url)
# if response.status == 200:
#     response_bytes = response.read()
#     response_text = response_bytes.decode('utf-8')
#     response_json = json.loads(response_text)
#     print(response_json['headers']['User-Agent'], response_json['args'])



url = 'http://httpbin.org/post?name=fcb'
data = {'age':'21', 'like':'eat'}
json_data = json.dumps(data)
res = request.Request(url, data=json_data.encode('utf-8'), headers={
'user-agent':'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/141.0.0.0 Safari/537.36',
'content-type':'application/json'
}, method='POST')
response = request.urlopen(res)

if response.status == 200:
    response_bytes = response.read()
    response_text = response_bytes.decode('utf-8')
    response_json = json.loads(response_text)
    print(response_json)






# url = 'http://httpbin.org/get?name=fcb'
# res = request.Request(url,headers = {
# 'user-agent':'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/141.0.0.0 Safari/537.36'
# })
# response = request.urlopen(res)
#
# if response.status == 200:
#     response_bytes = response.read()
#     response_text = response_bytes.decode('utf-8')
#     response_json = json.loads(response_text)
#     print(response_json['headers']['User-Agent'], response_json['args'])